// 解决输入输出

// 定义矩阵类型


// data 是个二维数组
function printMatrix(data,desc){
    // print("matrix: ->");
    console.log(desc)
    for(let i = 0;i <data.length;++i){
        let str = "  "
        for(let j = 0; j < data[0].length; ++ j){            
            str += (data[i][j] + " ");
        }        
        console.log(str);
    }
    
}


// 矩阵乘法
function multiplyMatrix(mat1,mat2){

    let count1 = mat1[0].length;
    let count2 = mat2.length
    if (count1 !== count2){
        console.error("两个矩阵不可相乘!!!");
        return;
    }

    printMatrix(mat1,"mat1")
    printMatrix(mat2,"mat2")
    let mat2_tmp = new Array()
    for(let i = 0;i < mat2[0].length;++i){
        mat2_tmp[i] = new Array()        
        for (j = 0;j < mat2.length;++j){
            mat2_tmp[i].push(mat2[j][i]);
        }
    }
    // console.log(mat2_tmp)

    let row = mat1.length;
    let col = mat2_tmp.length;

    let mat3 = new Array()
    for (let i = 0;i< row; ++i){   // 4
        mat3[i] = new Array()
        for(let j = 0; j < col;++j){ // 3
            let val = 0
            for(m = 0;m < count1;++m){
                val += mat1[i][m] * mat2_tmp[j][m];
                mat3[i][j] = val;
            }
        }
    }
    printMatrix(mat3,"mat3 -> ");
    return mat3;
}



multiplyMatrix([[1,2],[3,4],[5,6]],[[1,2,3],[4,5,6]]);
multiplyMatrix([[1,2,3],[4,5,6],[6,7,7]],[[1,2,3],[4,5,6],[7,7,7]]);


// usage: